﻿using System;
using System.Collections.Generic;
using System.IO;

namespace AVLTree
{
    class Program
    {
        static void Main(string[] args)
        {
            //平衡二叉树：左右两个子节点  相差高度不好过1

            List<string> words = new FileOperation(Directory.GetCurrentDirectory() + @"\Txt\pride-and-prejudice.txt").readFile();

            Console.WriteLine("Pride and Prejudice");

            Console.WriteLine("Total words: " + words.Count);

            AVLTree<string, int> batmap = new AVLTree<string, int>();
            foreach (var word in words)
            {
                if (batmap.contains(word))
                    batmap.set(word, batmap.get(word) + 1);
                else
                    batmap.add(word, 1);
            }

            Console.WriteLine("Total different words: " + batmap.getSize());
            Console.WriteLine("Frequency of PRIDE: " + batmap.get("pride"));
            Console.WriteLine("Frequency of PREJUDICE: " + batmap.get("prejudice"));
            Console.WriteLine("is BST : " + batmap.isBST());
            Console.WriteLine("is Balanced : " + batmap.isBalanced());


            //删除
            //foreach (var word in words)
            //{
            //    batmap.remove(word);
            //    if (!batmap.isBST() || !batmap.isBalanced())
            //        throw new Exception("Error");
            //}

            Console.WriteLine();
        }
    }
}
